package fr.ants.view.component;

import java.io.File;

import javax.swing.filechooser.FileFilter;

import fr.ants.utils.Formatter;

/**
 * {@link FileFilter} that allows CSV extension.
 * 
 */
public class CsvFileFilter extends FileFilter {

    /** allowed extension. */
    final static String CSV = "csv";

    /**
     * Constructor.
     */
    public CsvFileFilter() {
        // empty constructor
    }

    /*
     * Checks if the file is allowed.
     */
    @Override
    public boolean accept(final File file) {
        if (file.isDirectory()) {
            return true;
        }

        String extension = Formatter.getExtension(file);
        // check if the extension is csv
        if (extension != null) {
            if (extension.equals(CSV)) {
                return true;
            }
        }

        return false;
    }

    @Override
    public String getDescription() {
        return "Csv";
    }
    
    
}
